package com.xps.charminguser.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * AppCommond appCommond = new AppCommond.Builder()
 * .setOpration(AppCommond.CLOSE_ACTIVITY)
 * .setRequestcloseAcname("TeamActiveActivity")
 * .build();
 * EventBus.getDefault().post(appCommond);
 */

public class AppCommond {
    private int OPERATION = 0;//操作
    public static int CLOSE_ACTIVITY = 1;//命令
    private List<String> acNameList = new ArrayList<>();

    public void requestCloseActivity(String... toCloseAcName) {
        acNameList.clear();
        for (String name : toCloseAcName) {
            acNameList.add(name);
        }
    }

    public List<String> getAcNameList() {
        return acNameList;
    }

    public AppCommond() {
    }

    public int getOperation() {
        return OPERATION;
    }

    public void setOperation(int OPERATION) {
        this.OPERATION = OPERATION;
    }

    public static class Builder {
        AppCommond appCommond = null;

        public Builder() {
            appCommond = new AppCommond();
        }

        public Builder setOpration(int i) {
            appCommond.setOperation(i);
            return this;
        }

        /**
         * 添加想要关闭的Activity.getSimpleName
         */
        public Builder setRequestcloseAcname(String... name) {
            appCommond.requestCloseActivity(name);
            return this;
        }
        public AppCommond build() {
            return appCommond;
        }
    }

    public static boolean check(AppCommond a) {
        return (null != a && null != a.getAcNameList() && a.getAcNameList().size() > 0 && a.getOperation() == AppCommond.CLOSE_ACTIVITY);
    }

}
